package top.ffhome.game.ch05fix;

import javax.swing.*;
import java.awt.*;

public class BufferFrame extends JFrame {
    private Image iBuffer;
    private Graphics gBuffer;

    public BufferFrame(String title) {
        super(title);
    }

    @Override
    public void paint(Graphics g) {
        if (iBuffer == null) {
            iBuffer = createImage(this.getSize().width, this.getSize().height);
            gBuffer = iBuffer.getGraphics();
        }

        gBuffer.setColor(getBackground());
        gBuffer.fillRect(0, 0, this.getSize().width, this.getSize().height);

        paintBuffer(gBuffer);

        g.drawImage(iBuffer, 0, 0, this);
    }

    public void paintBuffer(Graphics g) {
    }
}
